//
//  MSHotelInfoCell.m
//  MSJD
//
//  Created by 箭军刘 on 2018/10/15.
//  Copyright © 2018年 xiangbo. All rights reserved.
//

#import "MSHotelSectionView.h"
#import "MSFilterHeadView.h"


NSInteger const kHotelSectionViewDefaultTag = 100000000;

@interface MSHotelSectionView()

@property (nonatomic, strong) MSFilterHeadView *filterHeadView;

@property (weak, nonatomic) IBOutlet UILabel *cityLabel; // 城市标签

@property (weak, nonatomic) IBOutlet UILabel *startDayLabel;
@property (weak, nonatomic) IBOutlet UILabel *endDayLabel;

@property (weak, nonatomic) IBOutlet UIButton *searchButton;
@property (weak, nonatomic) IBOutlet UIButton *clearButton; // 清理按钮

@property (nonatomic, copy) NSDictionary *filterInfo; // 筛选项数据

@end

@implementation MSHotelSectionView

+ (instancetype)loadHotelSectionViewWithFilterInfo:(NSDictionary *)filterInfo {
    MSHotelSectionView *hotelSection = [[[NSBundle mainBundle] loadNibNamed:@"MSHotelSectionView" owner:nil options:nil] firstObject];
    hotelSection.filterInfo = filterInfo;
    [hotelSection.filterHeadView refreshWithFilterInfo:filterInfo];
    return hotelSection;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self addSubview:self.filterHeadView];
    [self.filterHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.offset(0);
        make.height.offset(36.0);
    }];
}

- (void)showSectionFilterView {
    if (self.filterHeadView) {
        [self.filterHeadView startShowFilterView];
    }
}

- (void)refreshSectionDayLabel:(NSDictionary *)content {
    NSString *currentStr = [MSSafeObject stringInfo:content[@"current"]];
    NSString *tomorrow = [MSSafeObject stringInfo:content[@"tomorrow"]];
    // 刷新控件的数据
    self.startDayLabel.text = [NSString stringWithFormat:@"住 %@", [currentStr substringFromIndex:5]];
    self.endDayLabel.text = [NSString stringWithFormat:@"退 %@", [tomorrow substringFromIndex:5]];
}

- (void)refreshCityTitle:(NSString *)cityTitle {
    self.cityLabel.text = [MSSafeObject stringInfo:cityTitle];
}

- (void)changeSearchTitle:(NSString *)title {
    [self.searchButton setTitle:title forState:UIControlStateNormal];
    self.searchButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    self.clearButton.hidden = NO;
}

- (void)resetFilterSelectData {
    if (self.filterHeadView) {
        [self.filterHeadView reloatFilterData];
    }
}

#pragma mark - XIB Response

/** 顶部按钮点击回调 */
- (IBAction)sectionTopButtonClick:(UIButton *)sender {
    NSInteger tag = sender.tag - kHotelSectionViewDefaultTag;
    if (self.SectionTopButtonClickBlock) {
        self.SectionTopButtonClickBlock((MSHotelSectionButtonType)tag);
    }
}
- (IBAction)clearButtonClick:(id)sender {
    [self.searchButton setTitle:@"商圈/酒店/地址" forState:UIControlStateNormal];
    self.clearButton.hidden = YES;
    self.searchButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    if (self.SearchClearButtonClickBlock) {
        self.SearchClearButtonClickBlock();
    }
}

#pragma mark - Getters

- (MSFilterHeadView *)filterHeadView {
    if (!_filterHeadView) {
        _filterHeadView = [MSFilterHeadView loadFilterHeadViewWithIsHotel:YES];
        _WEAKSELF
        _filterHeadView.ShowFilterViewBlock = ^{
            if (weakSelf.FilterShowBlock) {
                weakSelf.FilterShowBlock(YES);
            }
        };
        _filterHeadView.HiddenFilterBlock = ^{
            if (weakSelf.FilterShowBlock) {
                weakSelf.FilterShowBlock(NO);
            }
//            weakSelf.tableView.scrollEnabled = YES;
        };
        
        _filterHeadView.ChangeFilterBlock = ^(NSDictionary * _Nonnull filterDic) {
            if (weakSelf.RefreshFilterBlock) {
                weakSelf.RefreshFilterBlock(filterDic);
            }
        };
    }
    return _filterHeadView;
}


@end
